001    /*
002     * AlignmentBlock.java
003     *
004     * Copyright 2003 Sergio Anibal de Carvalho Junior
005     *
006     * This file is part of NeoBio.
007     *
008     * NeoBio is free software; you can redistribute it and/or modify it under the terms of
009     * the GNU General Public License as published by the Free Software Foundation; either
010     * version 2 of the License, or (at your option) any later version.
011     *
012     * NeoBio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
013     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
014     * PURPOSE. See the GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License along with NeoBio;
017     * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
018     * Boston, MA 02111-1307, USA.
019     *
020     * Proper attribution of the author as the source of the software would be appreciated.
021     *
022     * Sergio Anibal de Carvalho Junior             mailto:sergioanibaljr@users.sourceforge.net
023     * Department of Computer Science               http://www.dcs.kcl.ac.uk
024     * King's College London, UK                    http://www.kcl.ac.uk
025     *
026     * Please visit http://neobio.sourceforge.net
027     *
028     * This project was supervised by Professor Maxime Crochemore.
029     *
030     */
031    
032    package neobio.alignment;
033    
034    /**
035     * This class is used by the {@linkplain CrochemoreLandauZivUkelson} algorithm to store
036     * the information of an alignment block. All fields are public (but final) in order to
037     * simplify the access to the data.
038     *
039     * <P>For more information on how this class is used, please refer to the specification
040     * of the <CODE>CrochemoreLandauZivUkelson</CODE> class and it subclasses.</P>
041     *
042     * @author Sergio A. de Carvalho Jr.
043     * @see CrochemoreLandauZivUkelson
044     */
045    public class AlignmentBlock
046    {
047            /**
048             * A pointer to the factor of the first sequence being aligned.
049             */
050            public final Factor factor1;
051    
052            /**
053             * A pointer to the factor of the second sequence being aligned.
054             */
055            public final Factor factor2;
056    
057            /**
058             * The DIST column of this block.
059             */
060            public final int[] dist_column;
061    
062            /**
063             * An array of pointers to prefix blocks of this block.
064             */
065            public final AlignmentBlock[] ancestor;
066    
067            /**
068             * This block's output border.
069             */
070            public final int[] output_border;
071    
072            /**
073             * An array of indexes to the source of the highest scoring path for each entry in
074             * the output border.
075             */
076            public final int[] source_path;
077    
078            /**
079             * An array of directions that must be followed to reach the source of the highest
080             * scoring path for each entry in the output border.
081             *
082             * @see CrochemoreLandauZivUkelson#STOP_DIRECTION
083             * @see CrochemoreLandauZivUkelson#LEFT_DIRECTION
084             * @see CrochemoreLandauZivUkelson#DIAGONAL_DIRECTION
085             * @see CrochemoreLandauZivUkelson#TOP_DIRECTION
086             */
087            public final byte[]     direction;
088    
089            /**
090             * Creates a new root block. A root block does not have <CODE>source_path</CODE> and
091             * <CODE>ancestor</CODE> arrays. Moreover, its <CODE>dist_column</CODE> and
092             * <CODE>output_border</CODE> arrays are set to zero, and the <CODE>direction</CODE>
093             * array is set to contain an <CODE>STOP_DIRECTION</CODE>.
094             *
095             * @param factor1 factor of the first sequence being aligned
096             * @param factor2 factor of the second sequence being aligned
097             */
098            public AlignmentBlock (Factor factor1, Factor factor2)
099            {
100                    this.factor1 = factor1;
101                    this.factor2 = factor2;
102    
103                    dist_column = output_border = new int[] {0};
104                    direction = new byte [] {0}; // STOP_DIRECTION
105                    source_path = null;
106                    ancestor = null;
107            }
108    
109            /**
110             * Creates a new alignment block, with all arrays created with the specified size.
111             *
112             * @param factor1 factor of the first sequence being aligned
113             * @param factor2 factor of the second sequence being aligned
114             * @param size size of the arrays to be created
115             */
116            public AlignmentBlock (Factor factor1, Factor factor2, int size)
117            {
118                    this.factor1 = factor1;
119                    this.factor2 = factor2;
120    
121                    dist_column = new int[size];
122                    output_border = new int[size];
123                    direction = new byte[size];
124                    source_path = new int[size];
125                    ancestor = new AlignmentBlock[size];
126            }
127    }